//
//  UIButton-Extension.swift
//  CJPWB
//
//  Created by 陈锦彭 on 16/3/13.
//  Copyright © 2016年 chenjinpeng. All rights reserved.
//

import UIKit

extension UIButton {
    // MARK: - 便利构造方法
    convenience init(imageName : String, bgImageName : String) {
        self.init()
        setBackgroundImage(UIImage(named: imageName), forState: .Normal)
        setBackgroundImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setImage(UIImage(named: bgImageName), forState: .Normal)
        setImage(UIImage(named:  bgImageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()

    }
    
    
    // MARK: - 类方法
    class func createBtn(imageName : String, bgImageName : String) -> UIButton {
        //创建button
        let btn = UIButton()
        //设置图片
        btn.setBackgroundImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        btn.setImage(UIImage(named: bgImageName), forState: .Normal)
        btn.setImage(UIImage(named:  bgImageName + "_highlighted"), forState: .Highlighted)
        btn.sizeToFit()
        return btn
    }
}
